﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.malls.MarketUI.view {
    import flash.events.*;
    import flash.display.*;
    import Mechanics.GameMechanicInterfaces.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import GameMode.*;
    import Display.aswingui.*;
    import Display.GridlistUI.model.*;
    import Display.aswingui.buttonui.*;

    public class MallBusinessCellView extends MallCellView {

        protected var m_busLevelDecoPane:AssetPane;
        protected var m_rightPanel:JPanel;
        protected var m_removePane:JPanel;
        protected var m_removeButton:JButton;
        protected var m_btnActionTxt:String;
        protected var m_bizTooltipShow:Boolean = false;
        protected var m_business:Business;
        protected var m_upgradeBtn:CustomButton;
        protected var m_fillBtn:CustomButton;

        public function MallBusinessCellView(_arg1:IMechanicUser, _arg2:int, _arg3:int, _arg4:Business=null){
            super(_arg1, _arg2, _arg3);
            this.m_busLevelDecoPane = new AssetPane();
            this.m_rightPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            this.m_business = _arg4;
        }
        protected function isSlotEmpty():Boolean{
            return ((this.m_business == null));
        }
        protected function get busLevelPanelBg():DisplayObject{
            return (m_assetDict["bg_footer"]);
        }
        override public function makeAssets(_arg1:Dictionary):void{
            var _local3:DisplayObject;
            super.makeAssets(_arg1);
            var _local2:DisplayObject = _arg1[DelayedAssetLoader.MALL_ASSETS];
            m_assetDict["bg"] = (new (_local2["mall_card_active"])() as DisplayObject);
            m_assetDict["bg_footer"] = (new (_local2["mall_card_footer"])() as DisplayObject);
            if (!this.isSlotEmpty()){
                _local3 = _arg1[DelayedAssetLoader.INVENTORY_ASSETS];
                m_assetDict["btn_close_small_up"] = (new (_local3["btn_close_small_up"])() as DisplayObject);
                m_assetDict["btn_close_small_over"] = (new (_local3["btn_close_small_over"])() as DisplayObject);
                m_assetDict["btn_close_small_down"] = (new (_local3["btn_close_small_down"])() as DisplayObject);
            };
        }
        override protected function initLayout():void{
            var _local1:JPanel;
            super.initLayout();
            if (!this.isSlotEmpty()){
                _local1 = this.makeRemoveButtonPanel();
                this.m_rightPanel.append(_local1);
                this.append(ASwingHelper.horizontalStrut(-49));
                this.append(this.m_rightPanel);
            };
            if (m_footPanel){
                if (!this.isSlotEmpty()){
                    this.initBusinessCellLayout();
                } else {
                    this.initEmptyBusinessCellLayout();
                };
            };
            ASwingHelper.setEasyBorder(m_panel, 0, 13, 0);
        }
        override public function updateView(_arg1):void{
            if (this.m_upgradeBtn){
                m_bodyPanelInsets.left = 3;
                updateBodyPanel();
            };
            ASwingHelper.prepare(this);
        }
        protected function initBusinessCellLayout():void{
            var _local1:Component;
            if (m_footPanel == null){
                return;
            };
            this.updateBusinessLevelDecoPane();
            if (((this.m_business) && (this.m_business.isUpgradePossible()))){
                this.m_btnActionTxt = TextFieldUtil.formatSmallCapsString(ZLoc.t("Dialogs", "Upgrade"));
                this.m_upgradeBtn = new CustomButton();
                this.m_upgradeBtn.setPreferredWidth((m_bodyPanel.getWidth() + 6));
                this.m_upgradeBtn.setText(this.m_btnActionTxt);
                this.m_upgradeBtn.setUI(new CoinsButtonUI());
                this.m_upgradeBtn.addEventListener(MouseEvent.CLICK, this.onUpgradeActionClick, false, 0, true);
                m_footPanel.append(this.m_upgradeBtn);
                ASwingHelper.setEasyBorder(this.m_upgradeBtn, 3, 1, 1, 2);
            } else {
                _local1 = this.m_busLevelDecoPane;
                m_footPanel.append(this.m_busLevelDecoPane);
                ASwingHelper.setEasyBorder(this.m_busLevelDecoPane, 3, -2, -2, 2);
            };
        }
        protected function initEmptyBusinessCellLayout():void{
            if (m_footPanel == null){
                return;
            };
            this.m_btnActionTxt = TextFieldUtil.formatSmallCapsString(ZLoc.t("Dialogs", "Fill"));
            this.m_fillBtn = new CustomButton();
            this.m_fillBtn.setPreferredWidth(m_bodyPanel.getWidth());
            this.m_fillBtn.setText(this.m_btnActionTxt);
            this.m_fillBtn.setUI(new CoinsButtonUI());
            this.m_fillBtn.addEventListener(MouseEvent.CLICK, this.onFillActionClick, false, 0, true);
            var _local1:ASFont = this.m_fillBtn.getFont();
            this.m_fillBtn.setFont(_local1.changeSize(TextFieldUtil.getLocaleFontSizeByRatio(_local1.getSize(), 1, [{
                locale:"de",
                ratio:0.8
            }, {
                locale:"id",
                ratio:0.8
            }, {
                locale:"es",
                ratio:0.9
            }, {
                locale:"fr",
                ratio:0.8
            }, {
                locale:"it",
                ratio:0.8
            }, {
                locale:"pt",
                ratio:0.8
            }, {
                locale:"tr",
                ratio:0.8
            }])));
            this.m_fillBtn.setPreferredWidth(m_bodyPanel.getWidth());
            m_footPanel.append(this.m_fillBtn);
            ASwingHelper.setEasyBorder(this.m_fillBtn, 3, 1, 1, 2);
        }
        override protected function createContentPlaceholder():DisplayObject{
            if (!this.isSlotEmpty()){
                return (super.createContentPlaceholder());
            };
            return (new Sprite());
        }
        protected function updateBusinessLevelDecoPane():void{
            if (this.busLevelPanelBg){
                this.busLevelPanelBg.alpha = 0.75;
                this.m_busLevelDecoPane.setAsset(this.busLevelPanelBg);
            };
        }
        protected function makeRemoveButtonPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.TOP);
            var _local2:DisplayObject = m_assetDict["btn_close_small_up"];
            var _local3:DisplayObject = m_assetDict["btn_close_small_over"];
            var _local4:DisplayObject = m_assetDict["btn_close_small_down"];
            this.m_removePane = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.RIGHT);
            this.m_removeButton = new JButton();
            this.m_removeButton.wrapSimpleButton(new SimpleButton(_local2, _local3, _local4, _local2));
            this.m_removeButton.addEventListener(MouseEvent.CLICK, this.onRemoveClick, false, 0, true);
            this.m_removeButton.addEventListener(MouseEvent.MOUSE_OVER, this.onRemoveOver, false, 0, true);
            this.m_removeButton.addEventListener(MouseEvent.MOUSE_OUT, this.onRemoveOut, false, 0, true);
            this.m_removePane.append(this.m_removeButton);
            this.m_removePane.append(ASwingHelper.horizontalStrut(27));
            ASwingHelper.prepare(this.m_removePane);
            _local1.append(this.m_removePane);
            ASwingHelper.prepare(_local1);
            this.m_rightPanel.setMaximumHeight(_local3.height);
            return (_local1);
        }
        public function disableCell():void{
            this.filters = [ASwingHelper.makeDisabledFilter()];
            this.m_removeButton.setEnabled(false);
        }
        public function enableCell():void{
            this.filters = [];
            this.m_removeButton.setEnabled(true);
        }
        protected function onRemoveClick(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
            this.disableCell();
            this.dispatchEvent(new ViewActionEvent("onRemove"));
        }
        protected function onRemoveOver(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
            if (this.m_bizTooltipShow){
                dispatchEvent(new Event("turnOffToolTip", true));
            };
        }
        protected function onRemoveOut(_arg1:MouseEvent):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
            if (this.m_bizTooltipShow){
                if (!this.isSlotEmpty()){
                    this.displayBusinessTooltip();
                } else {
                    this.displayEmptyCellTooltip();
                };
            };
        }
        protected function onFillActionClick(_arg1:MouseEvent=null):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
            if (!(Global.world.getTopGameMode() is GMMechanicStore)){
                this.dispatchEvent(new ViewActionEvent("onEnterStoreMode"));
                this.m_btnActionTxt = TextFieldUtil.formatSmallCapsString(ZLoc.t("Dialogs", "Cancel"));
                this.m_fillBtn.setText(this.m_btnActionTxt);
            } else {
                this.dispatchEvent(new ViewActionEvent("onExitStoreMode"));
                this.m_btnActionTxt = TextFieldUtil.formatSmallCapsString(ZLoc.t("Dialogs", "Fill"));
                this.m_fillBtn.setText(this.m_btnActionTxt);
            };
        }
        protected function onUpgradeActionClick(_arg1:MouseEvent=null):void{
            _arg1.stopPropagation();
            _arg1.stopImmediatePropagation();
            this.dispatchEvent(new ViewActionEvent("onUpgrade"));
        }
        override protected function onRollOver(_arg1:MouseEvent=null):void{
            this.m_bizTooltipShow = true;
            if (!this.isSlotEmpty()){
                this.displayBusinessTooltip();
            } else {
                this.displayEmptyCellTooltip();
            };
        }
        private function displayBusinessTooltip():void{
            this.dispatchEvent(new ViewActionEvent("onDisplayBusinessTooltip"));
        }
        private function displayEmptyCellTooltip():void{
            this.dispatchEvent(new ViewActionEvent("onDisplayEmptyCellTooltip"));
        }
        override protected function onRollOut(_arg1:MouseEvent=null):void{
            this.m_bizTooltipShow = false;
            dispatchEvent(new Event("turnOffToolTip", true));
        }

    }
}//package Modules.malls.MarketUI.view 
